import javax.swing.*;
import java.awt.*;

public class InfoPanel extends JPanel {
    private GamePanel gamePanel;
    private SkillTree skillTree = new SkillTree();

    public InfoPanel(GamePanel gamePanel) {
        this.gamePanel = gamePanel;
        setPreferredSize(new Dimension(300, GamePanel.ROWS * GamePanel.CELL_SIZE));
        setBackground(Color.BLACK);
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.WHITE);
        g.setFont(new Font("微软雅黑", Font.BOLD, 20));
        g.drawString("得分: " + gamePanel.score, 20, 40);
        g.setFont(new Font("微软雅黑", Font.PLAIN, 16));
        g.drawString("技能树", 20, 80);
        drawSkillTree(g, skillTree.root, 120, 120, 80);
        g.drawString("所有技能（共5个）：", 20, 320);
        g.drawString("技能树根、加速、分数加成、无敌、穿墙", 20, 340);
        g.drawString("最强技能（共2个）：", 20, 370);
        g.drawString("分数加成、穿墙", 20, 390);
    }

    private void drawSkillTree(Graphics g, SkillNode node, int x, int y, int dx) {
        if (node == null) return;
        g.setColor(Color.WHITE);
        g.drawRect(x-30, y-20, 60, 40);
        g.drawString(node.name, x-20, y+5);
        if (node.left != null) {
            g.drawLine(x, y+20, x-dx, y+80-20);
            drawSkillTree(g, node.left, x-dx, y+80, dx/2);
        }
        if (node.right != null) {
            g.drawLine(x, y+20, x+dx, y+80-20);
            drawSkillTree(g, node.right, x+dx, y+80, dx/2);
        }
    }
}